{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "#对series进行排序\n",
    "#s1 = pd.Series(np.random.randn(10))\n",
    "#s1\n",
    "#s1.values\n",
    "#s1.index\n",
    "#s1.sort_values() #从小到大排序\n",
    "#s1.sort_index()\n",
    "#df1 = pd.DataFrame(np.random.randn(40).reshape(8,5))\n",
    "# df1 = pd.read_csv('年度数据.csv',index_col=0,encoding='gb2312')\n",
    "# df1.sort_values() #默认为快速排序\n",
    "# df1['2021年'].sort_values(ascending=False)\n",
    "# df1.sort_values('2021年')\n",
    "# df1.sort_index(ascending=False)\n",
    "# 改变index\n",
    "# df1.index = pd.Series(['1','2','3'])\n",
    "# df1.index.map(str.upper) #传入function\n",
    "# df1.rename(index=str.lower,columns = str.upper) #也可以传入字典{需要改的:你改的值}\n",
    "#Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.971957\n",
       "1   -1.032187\n",
       "2   -0.554736\n",
       "3   -0.631938\n",
       "4   -1.128415\n",
       "5   -2.028830\n",
       "6   -0.010854\n",
       "7    0.432547\n",
       "8    0.390872\n",
       "9    0.760947\n",
       "dtype: float64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series(np.random.randn(10))\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=10, step=1)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.9719569 , -1.03218726, -0.55473566, -0.63193773, -1.12841465,\n",
       "       -2.02883005, -0.01085368,  0.43254707,  0.39087201,  0.76094672])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.971957\n",
       "9    0.760947\n",
       "7    0.432547\n",
       "8    0.390872\n",
       "6   -0.010854\n",
       "2   -0.554736\n",
       "3   -0.631938\n",
       "1   -1.032187\n",
       "4   -1.128415\n",
       "5   -2.028830\n",
       "dtype: float64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.sort_values(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9    0.760947\n",
       "8    0.390872\n",
       "7    0.432547\n",
       "6   -0.010854\n",
       "5   -2.028830\n",
       "4   -1.128415\n",
       "3   -0.631938\n",
       "2   -0.554736\n",
       "1   -1.032187\n",
       "0    1.971957\n",
       "dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1.sort_index(ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.read_csv('年度数据.csv',index_col=0,encoding='gb2312')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 10)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.sort_values(by=['2020年','2012年'],ascending=False)\n",
    "df1.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2021</th>\n",
       "      <th>2020年</th>\n",
       "      <th>2019年</th>\n",
       "      <th>2018年</th>\n",
       "      <th>2017年</th>\n",
       "      <th>2016年</th>\n",
       "      <th>2015年</th>\n",
       "      <th>2014年</th>\n",
       "      <th>2013年</th>\n",
       "      <th>2012年</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>指标</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>SSSSSS</th>\n",
       "      <td>24100.0</td>\n",
       "      <td>21210.0</td>\n",
       "      <td>21559.0</td>\n",
       "      <td>19853.0</td>\n",
       "      <td>18322.0</td>\n",
       "      <td>17111.0</td>\n",
       "      <td>15712.0</td>\n",
       "      <td>14491.0</td>\n",
       "      <td>13220.0</td>\n",
       "      <td>12054.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均消费支出比上年增长(%)</th>\n",
       "      <td>12.6</td>\n",
       "      <td>-4.0</td>\n",
       "      <td>5.5</td>\n",
       "      <td>6.2</td>\n",
       "      <td>5.4</td>\n",
       "      <td>6.8</td>\n",
       "      <td>6.9</td>\n",
       "      <td>7.5</td>\n",
       "      <td>6.9</td>\n",
       "      <td>8.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均服务性消费支出(元)</th>\n",
       "      <td>10645.0</td>\n",
       "      <td>9037.0</td>\n",
       "      <td>9886.0</td>\n",
       "      <td>8781.0</td>\n",
       "      <td>7803.0</td>\n",
       "      <td>7157.0</td>\n",
       "      <td>6460.0</td>\n",
       "      <td>5842.0</td>\n",
       "      <td>5246.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均服务性消费支出比上年增长(%)</th>\n",
       "      <td>17.8</td>\n",
       "      <td>-8.6</td>\n",
       "      <td>12.6</td>\n",
       "      <td>12.5</td>\n",
       "      <td>9.0</td>\n",
       "      <td>10.8</td>\n",
       "      <td>10.6</td>\n",
       "      <td>11.4</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均食品烟酒支出(元)</th>\n",
       "      <td>7178.0</td>\n",
       "      <td>6397.0</td>\n",
       "      <td>6084.0</td>\n",
       "      <td>5631.0</td>\n",
       "      <td>5374.0</td>\n",
       "      <td>5151.0</td>\n",
       "      <td>4814.0</td>\n",
       "      <td>4494.0</td>\n",
       "      <td>4127.0</td>\n",
       "      <td>3983.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均食品烟酒支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5.1</td>\n",
       "      <td>8.0</td>\n",
       "      <td>4.8</td>\n",
       "      <td>4.3</td>\n",
       "      <td>7.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>8.9</td>\n",
       "      <td>3.6</td>\n",
       "      <td>9.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均衣着支出(元)</th>\n",
       "      <td>1419.0</td>\n",
       "      <td>1238.0</td>\n",
       "      <td>1338.0</td>\n",
       "      <td>1289.0</td>\n",
       "      <td>1238.0</td>\n",
       "      <td>1203.0</td>\n",
       "      <td>1164.0</td>\n",
       "      <td>1099.0</td>\n",
       "      <td>1027.0</td>\n",
       "      <td>992.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均衣着支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-7.5</td>\n",
       "      <td>3.8</td>\n",
       "      <td>4.1</td>\n",
       "      <td>2.9</td>\n",
       "      <td>3.3</td>\n",
       "      <td>5.9</td>\n",
       "      <td>7.0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>9.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均居住支出(元)</th>\n",
       "      <td>5641.0</td>\n",
       "      <td>5215.0</td>\n",
       "      <td>5055.0</td>\n",
       "      <td>4647.0</td>\n",
       "      <td>4107.0</td>\n",
       "      <td>3746.0</td>\n",
       "      <td>3419.0</td>\n",
       "      <td>3201.0</td>\n",
       "      <td>2999.0</td>\n",
       "      <td>2480.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均居住支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>3.2</td>\n",
       "      <td>8.8</td>\n",
       "      <td>13.1</td>\n",
       "      <td>9.6</td>\n",
       "      <td>9.6</td>\n",
       "      <td>6.8</td>\n",
       "      <td>6.7</td>\n",
       "      <td>20.9</td>\n",
       "      <td>12.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均生活用品及服务支出(元)</th>\n",
       "      <td>1423.0</td>\n",
       "      <td>1260.0</td>\n",
       "      <td>1281.0</td>\n",
       "      <td>1223.0</td>\n",
       "      <td>1121.0</td>\n",
       "      <td>1044.0</td>\n",
       "      <td>951.0</td>\n",
       "      <td>890.0</td>\n",
       "      <td>806.0</td>\n",
       "      <td>741.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均生活用品及服务支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-1.7</td>\n",
       "      <td>4.8</td>\n",
       "      <td>9.1</td>\n",
       "      <td>7.4</td>\n",
       "      <td>9.7</td>\n",
       "      <td>6.9</td>\n",
       "      <td>10.3</td>\n",
       "      <td>8.8</td>\n",
       "      <td>9.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均交通通信支出(元)</th>\n",
       "      <td>3156.0</td>\n",
       "      <td>2762.0</td>\n",
       "      <td>2862.0</td>\n",
       "      <td>2675.0</td>\n",
       "      <td>2499.0</td>\n",
       "      <td>2338.0</td>\n",
       "      <td>2087.0</td>\n",
       "      <td>1869.0</td>\n",
       "      <td>1627.0</td>\n",
       "      <td>1451.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均交通通信支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-3.5</td>\n",
       "      <td>7.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>6.9</td>\n",
       "      <td>12.0</td>\n",
       "      <td>11.6</td>\n",
       "      <td>14.9</td>\n",
       "      <td>12.2</td>\n",
       "      <td>15.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均教育文化娱乐支出(元)</th>\n",
       "      <td>2599.0</td>\n",
       "      <td>2032.0</td>\n",
       "      <td>2513.0</td>\n",
       "      <td>2226.0</td>\n",
       "      <td>2086.0</td>\n",
       "      <td>1915.0</td>\n",
       "      <td>1723.0</td>\n",
       "      <td>1536.0</td>\n",
       "      <td>1398.0</td>\n",
       "      <td>1262.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均教育文化娱乐支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-19.1</td>\n",
       "      <td>12.9</td>\n",
       "      <td>6.7</td>\n",
       "      <td>8.9</td>\n",
       "      <td>11.2</td>\n",
       "      <td>12.2</td>\n",
       "      <td>9.9</td>\n",
       "      <td>10.8</td>\n",
       "      <td>11.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均医疗保健支出(元)</th>\n",
       "      <td>2115.0</td>\n",
       "      <td>1843.0</td>\n",
       "      <td>1902.0</td>\n",
       "      <td>1685.0</td>\n",
       "      <td>1451.0</td>\n",
       "      <td>1307.0</td>\n",
       "      <td>1165.0</td>\n",
       "      <td>1045.0</td>\n",
       "      <td>912.0</td>\n",
       "      <td>838.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均医疗保健支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-3.1</td>\n",
       "      <td>12.9</td>\n",
       "      <td>16.1</td>\n",
       "      <td>11.0</td>\n",
       "      <td>12.3</td>\n",
       "      <td>11.5</td>\n",
       "      <td>14.5</td>\n",
       "      <td>8.8</td>\n",
       "      <td>12.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均其他用品及服务支出(元)</th>\n",
       "      <td>569.0</td>\n",
       "      <td>462.0</td>\n",
       "      <td>524.0</td>\n",
       "      <td>477.0</td>\n",
       "      <td>447.0</td>\n",
       "      <td>406.0</td>\n",
       "      <td>389.0</td>\n",
       "      <td>358.0</td>\n",
       "      <td>325.0</td>\n",
       "      <td>307.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>居民人均其他用品及服务支出比上年增长(%)</th>\n",
       "      <td>NaN</td>\n",
       "      <td>-11.8</td>\n",
       "      <td>9.7</td>\n",
       "      <td>6.8</td>\n",
       "      <td>10.0</td>\n",
       "      <td>4.4</td>\n",
       "      <td>8.7</td>\n",
       "      <td>10.3</td>\n",
       "      <td>5.6</td>\n",
       "      <td>12.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          2021    2020年    2019年    2018年    2017年    2016年  \\\n",
       "指标                                                                            \n",
       "SSSSSS                 24100.0  21210.0  21559.0  19853.0  18322.0  17111.0   \n",
       "居民人均消费支出比上年增长(%)          12.6     -4.0      5.5      6.2      5.4      6.8   \n",
       "居民人均服务性消费支出(元)         10645.0   9037.0   9886.0   8781.0   7803.0   7157.0   \n",
       "居民人均服务性消费支出比上年增长(%)       17.8     -8.6     12.6     12.5      9.0     10.8   \n",
       "居民人均食品烟酒支出(元)           7178.0   6397.0   6084.0   5631.0   5374.0   5151.0   \n",
       "居民人均食品烟酒支出比上年增长(%)         NaN      5.1      8.0      4.8      4.3      7.0   \n",
       "居民人均衣着支出(元)             1419.0   1238.0   1338.0   1289.0   1238.0   1203.0   \n",
       "居民人均衣着支出比上年增长(%)           NaN     -7.5      3.8      4.1      2.9      3.3   \n",
       "居民人均居住支出(元)             5641.0   5215.0   5055.0   4647.0   4107.0   3746.0   \n",
       "居民人均居住支出比上年增长(%)           NaN      3.2      8.8     13.1      9.6      9.6   \n",
       "居民人均生活用品及服务支出(元)        1423.0   1260.0   1281.0   1223.0   1121.0   1044.0   \n",
       "居民人均生活用品及服务支出比上年增长(%)      NaN     -1.7      4.8      9.1      7.4      9.7   \n",
       "居民人均交通通信支出(元)           3156.0   2762.0   2862.0   2675.0   2499.0   2338.0   \n",
       "居民人均交通通信支出比上年增长(%)         NaN     -3.5      7.0      7.1      6.9     12.0   \n",
       "居民人均教育文化娱乐支出(元)         2599.0   2032.0   2513.0   2226.0   2086.0   1915.0   \n",
       "居民人均教育文化娱乐支出比上年增长(%)       NaN    -19.1     12.9      6.7      8.9     11.2   \n",
       "居民人均医疗保健支出(元)           2115.0   1843.0   1902.0   1685.0   1451.0   1307.0   \n",
       "居民人均医疗保健支出比上年增长(%)         NaN     -3.1     12.9     16.1     11.0     12.3   \n",
       "居民人均其他用品及服务支出(元)         569.0    462.0    524.0    477.0    447.0    406.0   \n",
       "居民人均其他用品及服务支出比上年增长(%)      NaN    -11.8      9.7      6.8     10.0      4.4   \n",
       "\n",
       "                         2015年    2014年    2013年    2012年  \n",
       "指标                                                         \n",
       "SSSSSS                 15712.0  14491.0  13220.0  12054.0  \n",
       "居民人均消费支出比上年增长(%)           6.9      7.5      6.9      8.6  \n",
       "居民人均服务性消费支出(元)          6460.0   5842.0   5246.0      NaN  \n",
       "居民人均服务性消费支出比上年增长(%)       10.6     11.4      NaN      NaN  \n",
       "居民人均食品烟酒支出(元)           4814.0   4494.0   4127.0   3983.0  \n",
       "居民人均食品烟酒支出比上年增长(%)         7.1      8.9      3.6      9.6  \n",
       "居民人均衣着支出(元)             1164.0   1099.0   1027.0    992.0  \n",
       "居民人均衣着支出比上年增长(%)           5.9      7.0      3.6      9.9  \n",
       "居民人均居住支出(元)             3419.0   3201.0   2999.0   2480.0  \n",
       "居民人均居住支出比上年增长(%)           6.8      6.7     20.9     12.8  \n",
       "居民人均生活用品及服务支出(元)         951.0    890.0    806.0    741.0  \n",
       "居民人均生活用品及服务支出比上年增长(%)      6.9     10.3      8.8      9.8  \n",
       "居民人均交通通信支出(元)           2087.0   1869.0   1627.0   1451.0  \n",
       "居民人均交通通信支出比上年增长(%)        11.6     14.9     12.2     15.3  \n",
       "居民人均教育文化娱乐支出(元)         1723.0   1536.0   1398.0   1262.0  \n",
       "居民人均教育文化娱乐支出比上年增长(%)      12.2      9.9     10.8     11.1  \n",
       "居民人均医疗保健支出(元)           1165.0   1045.0    912.0    838.0  \n",
       "居民人均医疗保健支出比上年增长(%)        11.5     14.5      8.8     12.7  \n",
       "居民人均其他用品及服务支出(元)         389.0    358.0    325.0    307.0  \n",
       "居民人均其他用品及服务支出比上年增长(%)      8.7     10.3      5.6     12.9  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#df1.index = pd.Series([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])\n",
    "\n",
    "df1 = df1.rename(index={'居民人均消费支出(元)':'ssssss'},columns = {'2021年':'2021'}) \n",
    "df1.index = df1.index.map(str.upper)\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Numpy数组合并\n",
    "x = np.array([[1,2,3]])\n",
    "y = np.array([[4,5,6]])\n",
    "np.concatenate((x,y),axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    a\n",
       "2    b\n",
       "3    c\n",
       "dtype: object"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series(['a','b','c'],index = [1,2,3])\n",
    "s2 =  pd.Series(['d','e','f'],index = [2,5,7])\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2    d\n",
       "5    e\n",
       "7    f\n",
       "dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    a\n",
       "2    b\n",
       "3    c\n",
       "2    d\n",
       "5    e\n",
       "7    f\n",
       "dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([s1,s2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A1</td>\n",
       "      <td>B1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A2</td>\n",
       "      <td>B2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B\n",
       "1  A1  B1\n",
       "2  A2  B2"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def make_df(cols,ind):\n",
    "    data = {c:[str(c)+str(i)for i in ind] for c in cols}\n",
    "    return pd.DataFrame(data,ind)\n",
    "\n",
    "df1 = make_df('AB',[1,2])\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A3</td>\n",
       "      <td>B3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>A4</td>\n",
       "      <td>B4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A   B\n",
       "3  A3  B3\n",
       "4  A4  B4"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = make_df('AB',[3,4])\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [A, B]\n",
       "Index: []"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df1,df2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
